package com.sam.im.sms.index.activitys;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;

import com.sam.im.sms.R;
import com.sam.im.sms.base.BaseActivity;
import com.sam.im.sms.setting.SMSSettingImpl;
import com.sam.im.sms.setting.Setting;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 描述
 * liuyucheng
 * Created By 刘育成 on 2019/6/3.
 */
public class SmsSettingActivity extends BaseActivity implements CompoundButton.OnCheckedChangeListener, View.OnClickListener {

    private LinearLayout mLlLayout;
    private TextView mTvBack;
    private TextView mTextView;
    private Switch mIsVerify;
    private RelativeLayout mReLayoutRule;
    private Switch mIsRemind;
    private RelativeLayout mReLayoutBlack;
    private RelativeLayout mReLayoutWhite;


    Setting mSetting;
    boolean verify;
    boolean remind;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }

    @Override
    public int getContentViewId() {
        return R.layout.activity_sms_setting;
    }

    @Override
    public void init(Bundle savedInstanceState) {
        mSetting = SMSSettingImpl.getInstance();
        initView();
        updataUI();
    }

    private void initView() {
        mLlLayout = (LinearLayout) findViewById(R.id.ll_layout);
        mTvBack = (TextView) findViewById(R.id.tv_back);
        mTextView = (TextView) findViewById(R.id.textView);
        mIsVerify = (Switch) findViewById(R.id.is_verify);
        mReLayoutRule = (RelativeLayout) findViewById(R.id.re_layout_rule);
        mIsRemind = (Switch) findViewById(R.id.is_remind);
        mReLayoutBlack = (RelativeLayout) findViewById(R.id.re_layout_black);
        mReLayoutWhite = (RelativeLayout) findViewById(R.id.re_layout_white);
        mTvBack.setOnClickListener(this::onClick);
        mReLayoutRule.setOnClickListener(this::onClick);
        mReLayoutBlack.setOnClickListener(this::onClick);
        mReLayoutWhite.setOnClickListener(this::onClick);
    }

    private void updataUI() {
        verify = mSetting.isVerify("isVerify");
        remind = mSetting.isRemind("isRemind");
        mIsVerify.setChecked(verify);
        mIsRemind.setChecked(remind);
        mIsVerify.setOnCheckedChangeListener(this::onCheckedChanged);
        mIsRemind.setOnCheckedChangeListener(this::onCheckedChanged);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_back:
                finish();
                break;
            //黑名单
            case R.id.re_layout_black:
                startActivity(BlackListActivity.class);
                break;
            //拦截规则
            case R.id.re_layout_rule:
                startActivity(RuleActivity.class);
                break;
            //白名单
            case R.id.re_layout_white:
                startActivity(WhiteListActivity.class);
                break;
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

        switch (buttonView.getId()) {
            case R.id.is_verify:
                mSetting.setVerify("isVerify", isChecked);
                mSetting.setRemind("isRemind", isChecked);
                mIsRemind.setChecked(isChecked);
                break;
            case R.id.is_remind:
                mSetting.setRemind("isRemind", isChecked);
                break;
        }
    }


    /**
     * 判断
     * 1 true      0 false
     */
    public boolean judgeValue(String value) {
        return "1".equals(value);
    }
}
